<template>
  <div class="mer-notification-container" :class="isShow ? 'show-wrap' : 'hidden-wrap'">
    <div class="title-wrap">
      <slot name="header">
        <div class="mer-title">
          {{bigTitle}}
        </div>
      </slot>
      <slot name="close" v-if="isShowClose">
        <i class="el-icon-close mer-icon" @click="handleView(false)"></i>
      </slot>
    </div>
    <div class="content-wrap">
      <slot name="content">
        <div class="mer-content">
          <div class="mer-content-title">
            {{noticeObj.noticeTitle}}
          </div>
          <div class="mer-content-des">
            {{noticeObj.noticeContent}}
          </div>
        </div>
      </slot>
      <div class="mer-footer-wrap">
        <slot name="footer">
          <div class="view-btn" @click="handleView(true)">查看</div>
        </slot>
      </div>
    </div>
  </div>
</template>

<script>
import { addTimes } from '@/api/marketFund'
export default {
  name: 'notification',
  props: {
    isShowClose: {
      type: Boolean,
      default: true
    },
    bigTitle: {
      type: String,
      default: '能链云团油'
    },
    noticeObj: {
      type: Object,
      default: () => ({
        noticeTitle: '',
        noticeContent: '',
        noticeId: '',
        gasId: ''
      })
    },
    isShow: {
      type: Boolean,
      default: false
    }
  },
  methods: {
    handleView (type) {
      this.$emit('update:isShow', false)
      const params = {
        noticeId: this.noticeObj.noticeId
      }
      if (params.noticeId) this.addTimes(type, params)
    },
    // 添加消息已读次数
    async addTimes (type, params) {
      try {
        const { code } = await addTimes(params)
        if (code !== 200) return
        if (type) this.$router.push({ path: '/fund/marketFund', query: { gasId: this.noticeObj.gasId } })
        this.$emit('closeNotifi', { ...params, type })
      } catch (error) {
        console.log(error.message)
      }
    }
  }
}
</script>

<style lang="less" scoped>
.mer-notification-container{
  position: fixed;
  z-index: 3001;
  bottom: 40px;
  right: 42px;
  width: 343px;
  // height: 240px;
  font-family: PingFangSC-Regular, PingFang SC;
  font-weight: 400;
  box-shadow: 0px 8px 21px 0px rgba(0,0,0,0.12);
  border-radius: 3px;
  transition: all .3s ease 0s;
  overflow: hidden;
  background-color: #fff;
  &.hidden-wrap{
    bottom: -264px;
    opacity: 0;
  }
  &.show-wrap{
    bottom: 40px;
    opacity: 1;
  }
  .title-wrap{
    width: 100%;
    height: 42px;
    padding: 15px 17px;
    box-sizing: border-box;
    background-color: #4B7EFE;
    border-radius: 3px 3px 0px 0px;
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    .mer-title{
      flex: 1;
      text-align: center;
      font-size: 15px;
      font-weight: 600;
      font-family: PingFangSC-Semibold, PingFang SC;
      color: #FFFFFF;
    }
  }
  .content-wrap{
    padding: 17px 28px 20px 28px;
    box-sizing: border-box;
    width: 100%;
    background-color: #fff;
    .mer-content{
      font-size: 12px;
      font-family: PingFangSC-Regular, PingFang SC;
      font-weight: 400;
      width: 100%;
      margin-bottom: 17px;
      .mer-content-title{
        color: #222222;
        margin-bottom: 5px;
      }
      .mer-content-des{
        min-height: 80px;
        white-space: wrap;
        color: #222222;
        line-height: 20px;
      }
    }
  }
  .mer-footer-wrap{
    width: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
    .view-btn{
      width: 85px;
      height: 31px;
      background: #4B7EFE;
      border-radius: 3px;
      font-size: 13px;
      font-family: PingFangSC-Medium, PingFang SC;
      font-weight: 500;
      color: #FFFFFF;
      line-height: 31px;
      text-align: center;
      cursor: pointer;
    }
  }
  .mer-icon{
    font-size: 15px;
    color: white;
    cursor: pointer;
  }
}
</style>